// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');


module.exports = $;

// 引入Swiper

var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');

var swiper = new Swiper('.swiper-container', {//开始进入前的方块旋转
        pagination: '.swiper-pagination',
        effect: 'cube',
        grabCursor: true,
        cube: {
            shadow: true,
            slideShadows: true,
            shadowOffset: 20,
            shadowScale: 0.94
        },
         onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
            swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
            swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
        }, 
        onSlideChangeEnd: function(swiper){ 
            swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
        }
    }); 


var IScroll = require('./components/iscroll/iscroll');
var isPassive = require('./components/dateUtil');

 $("#mainContainer").hide();
 $(".swiper-container").hide();
// jquery/zepto
$("#enter").tap(function(){
    $(".swiper-container").hide();
    $("#mainContainer").show();

    myScroll = new IScroll('#wrapper', {  useTransition: false  });
    document.addEventListener('touchmove', function (e) { e.preventDefault(); }, isPassive() ? {
	capture: false,
	passive: false
} : false);
function getproject(){
    $.ajax({
        type:'GET',
        url:'http://10.31.160.68:7000/api/project.php',
        dataType:'json',
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +='<li>' + data[i].name + 
                '<p>'+data[i].url+'</p>'+
                '<p>'+data[i].description+'</p>' + 
                '<p>'+data[i].detail+'</p>'+
                '<p>'+data[i].tech+'</p>' + 
                '</li>';
            }
            $("#scroller ul").html(html);
        }
    })}
    getproject();
})
$("#footer ul li").first().css("color","green")
  $('#footer ul li').tap(function(){
    $(this).addClass('active').siblings().removeClass('active');
    var url;
    switch ($(this).index()) {
      case 0:getproject();
        break;
      case 1:getskill();
        break;
      case 2:getwork();
        break;
      case 3:getme();
        break;
      default:
        break;
    }

   function getproject(){
    $.ajax({
        type:'GET',
        url:'http://10.31.160.68:7000/api/project.php',
        dataType:'json',
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +='<li>' + data[i].name + 
                '<p>'+data[i].url+'</p>'+
                '<p>'+data[i].description+'</p>' + 
                '<p>'+data[i].detail+'</p>'+
                '<p>'+data[i].tech+'</p>' + 
                '</li>';
            }
            $("#scroller ul").html(html);
        }
    })
}

    function getskill(){
         $.ajax({
          type:'post',
          url:'http://10.31.160.68:7000/api/skill.php',
          dataType:'json',
          success:function(d){
            var data = d;
            var html='';
            for(var i=0;i<data.length;i++){
              html+='<li class="on">';
              html+='<div class="skill-title">'+data[i].category+'</div>';
              html+='<div class="skill-name">';
              html+='<span>技术：</span><span>'+data[i].name+'</span>';
              html+='</div>';
              html+='<div class="skill-all">';
              html+='<div class="skill-time"><span>时间：</span><span>'+data[i].time+'</span></div>';
              html+='<div class="skill-level"><span>程度：</span><span>'+data[i].level+'</span></div>';
              html+='</div>';
              html+='</li>';
            }
            $('#scroller ul').html(html);
          }
        })
    }
    
    function getwork(){
      $.ajax({
        type:'post',
        url:'http://10.31.160.68:7000/api/work.php',
        dataType:'json',
        success:function(d){
          var data=d;
          var html='';
          for(var i=0;i<data.length;i++){
            html+='<li class="work">'+
						'<div class="work-pic">'+
						'</div>'+
						'<div class="work-name">'+data[i].name+'</div>'+
						'<div class="work-posts">'+
            '<span>岗位：</span><span>'+data[i].posts+'</span>'+
						'</div>'+
						'<div class="work-time">'+
            '<span>任职时间：</span><span>'+data[i].time+'</span>'+
						'</div>'+
						'<div class="work-peoples">'+
            '<span>人数：</span><span>'+data[i].peoples+'</span>'+
						'</div>'+
						'<div class="work-project">'+
						'<span>项目：</span>'+data[i].projects+'</span>'+
						'</div>'+
					  '</li>';
          }
          $('#scroller ul').html(html);
        }
      })
    }
    function getme(){
      $.ajax({
        type:'post',
        url:'http://10.31.160.68:7000/api/me.php',
        dataType:'json',
        success:function(d){
          var data=d;
          var html='';
            html+='<li class="work">'+
						'<div class="work-pic">'+
                            '<img src="../images/pic.jpg" width="100px">'+
                           ' <div>姓名：&nbsp;&nbsp;'+data[0].name+'</div>'+
                           ' <div>年龄：&nbsp;&nbsp;'+data[0].age+'</div>'+
                           ' <div>性别：&nbsp;&nbsp;'+data[0].sex+'</div>'+
                            ' <div>性别：&nbsp;&nbsp;'+data[0].school+'</div>'+
						'</div>'+
					  '</li>';
          
          $('#scroller ul').html(html);
        }
      })
    }
    $(this).css('color','green').siblings().css('color','white');

})

var interval  = setInterval(function(){
    if(document.readyState === 'complete'){
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    }else{
        $("#loading").show();
    }
})